package com.chis.jmdatatimer.comm;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

/**
 * @author wlj
 * @version 2018年01月25日
 * @Description
 * @Company zwx
 */
public class PropertyConfigurer {
    /**
     * 属性值
     */
    private static Map<String, String> propertyMap = null;

    private static void initPropertyMap() {
        propertyMap = new HashMap<>();
        Properties prop = new Properties();
        try {
            InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
            prop.load(in);
            Iterator<String> it = prop.stringPropertyNames().iterator();
            while (it.hasNext()) {
                String key = it.next();
                propertyMap.put(key,prop.getProperty(key));
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取属性
     *
     * @param name 属性名称
     * @return 属性值
     */
    public static String getProperty(String name) {
        if (propertyMap == null) {
            initPropertyMap();
        }
        return propertyMap.get(name);
    }

}
